package com.easepal7506a.project.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by FHB on 2018/4/18.
 */
public class TimeObserver {

    private static TimeObserver mInst = null;
    private static Object mLock = new Object();

    private List<onTimeUpdataLis> mOnCloseListerner;

    private TimeObserver(){
        mOnCloseListerner = new ArrayList<onTimeUpdataLis>();
    }

    public static TimeObserver getInst(){
        if(mInst == null){
            synchronized(mLock){
                if(mInst == null){
                    mInst = new TimeObserver();
                }
            }
        }
        return mInst;
    }

    public void  registerObserver(onTimeUpdataLis action){
        if(!mOnCloseListerner.contains(action)){
            mOnCloseListerner.add(action);
        }
    }

    public void removeObserver(onTimeUpdataLis action){
        mOnCloseListerner.remove(action);
    }


    public void noticeTimeChange(String min,String sec){
        for (int i = 0; i < mOnCloseListerner.size(); i++) {
            try {
                mOnCloseListerner.get(i).onupdataTime(min,sec);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public interface onTimeUpdataLis {
        void onupdataTime(String min,String sec);


    }


}
